﻿using System;
using System.Windows.Forms;
using dk.Helper.Base;

namespace dk.Helper.Controls
{
    public partial class WorldMapFilterForm : Form
    {
        private readonly IWorldMapFilter worldMapFilter;

        public WorldMapFilterForm(IWorldMapFilter worldMapFilter)
        {
            this.worldMapFilter = worldMapFilter;
            InitializeComponent();
            chbShowAbandonedVillages.Checked = worldMapFilter.ShowAbandonedVillages;
            chbPlayersWithoutAlly.Checked = worldMapFilter.ShowPlayersWithoutAlly;
            nudMinVillagePoints.Value = worldMapFilter.VillagePoints.Start;
            nudMaxVillagePoints.Value = worldMapFilter.VillagePoints.End;
            nudMinPlayerPoints.Value = worldMapFilter.PlayerPoints.Start;
            nudMaxPlayerPoints.Value = worldMapFilter.PlayerPoints.End;
            chbVillagePoints.Checked = worldMapFilter.VillagePoints.IsDefined;
            chbPlayerPoints.Checked = worldMapFilter.PlayerPoints.IsDefined;
        }

        private void chbVillagePoints_CheckedChanged(object sender, EventArgs e)
        {
            nudMinVillagePoints.Enabled = chbVillagePoints.Checked;
            nudMaxVillagePoints.Enabled = chbVillagePoints.Checked;
            worldMapFilter.VillagePoints.IsDefined = chbVillagePoints.Checked;
        }

        private void chbPlayerPoints_CheckedChanged(object sender, EventArgs e)
        {
            nudMinPlayerPoints.Enabled = chbPlayerPoints.Checked;
            nudMaxPlayerPoints.Enabled = chbPlayerPoints.Checked;
            worldMapFilter.PlayerPoints.IsDefined = chbPlayerPoints.Checked;
        }

        private void chbShowAbandonedVillages_CheckedChanged(object sender, EventArgs e)
        {
            worldMapFilter.ShowAbandonedVillages = chbShowAbandonedVillages.Checked;
        }

        private void chbPlayersWithoutAlly_CheckedChanged(object sender, EventArgs e)
        {
            worldMapFilter.ShowPlayersWithoutAlly = chbPlayersWithoutAlly.Checked;
        }

        private void nudMinVillagePoints_ValueChanged(object sender, EventArgs e)
        {
            worldMapFilter.VillagePoints.Start = (int) nudMinVillagePoints.Value;
        }

        private void nudMaxVillagePoints_ValueChanged(object sender, EventArgs e)
        {
            worldMapFilter.VillagePoints.End = (int) nudMaxVillagePoints.Value;
        }

        private void nudMinPlayerPoints_ValueChanged(object sender, EventArgs e)
        {
            worldMapFilter.PlayerPoints.Start = (int) nudMinPlayerPoints.Value;
        }

        private void nudMaxPlayerPoints_ValueChanged(object sender, EventArgs e)
        {
            worldMapFilter.PlayerPoints.End = (int) nudMaxPlayerPoints.Value;
        }
    }
}